home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / embedded / m68k / fbug68k.arc / BM.C < prev    next >
C/C++ Source or Header  |  1989-08-17  |  5KB  |  145 lines

  1. #include"userdef.h"
  2.  
  3. /* ****************************************************** */
  4. /*
  5. bm [<size>] <range> <addr>
  6. Block Move -> This command moves a block of memory bounded by <range>
  7. to memory starting at <addr> in increments of <size>.
  8.  
  9. The objective of this command is to allow you to shift data up or down
  10. in memory. For example, if you needed to insert a line of code into memory,
  11. then you could clear out the appropriate amount of space with a block
  12. move, then use the line assembler to insert the new line. The move is 
  13. not destructive to the area moved from, unless the <addr> moved to falls within
  14. the <range> moved from.
  15.  
  16. The <size> is only used if the <range> is described as <addr>:count, not
  17. <addr>,<addr>. If <addr>,<addr> is used, then the <size> defaults to
  18. byte. This means a faster block move can be made by using <addr>,<count>
  19. and specifying the <size> as 32 bits (L for 68k, W for 88K).
  20.  
  21. The first thing done is to check to see if the right number of arguments
  22. are on the command line. To many or to few results in an error.
  23.  
  24. If the number of arguments on the command line are correct, then the "bm "
  25. is stripped from the start of the command line. Next the size option, if any,
  26. is obtained. A check is made to see if <range> is in the form of
  27. <addr>,<count>. If not then the size defaults to 1 byte so that getcount
  28. won't truncate any of the <range>. The starting address, then the count
  29. is obtained. Finally, an address is obtained from the command line.
  30. If any of the command line arguments are incorrect, then an error
  31. message is displayed and no memory is moved. If all are correct, then
  32. the starting and ending address of the area from which the memory
  33. will be used to the area the memory will fill.
  34.  
  35. Now that the command line has been successfully parsed, the data will
  36. actually be moved. To ensure proper transfer, if the starting address
  37. is lower than the address the memory data is being moved to, then the
  38. data will be moved from high memory to low memory. Otherwise, the
  39. memory will be moved from low memory to high memory.
  40.  
  41. The loop that does the actual memory move gets memory from the source location,
  42. puts it in the destination location. Moves the from address (start)
  43. towards the destination address. The count of the number if 1, 2 or 4 byte
  44. increments of data is decremented and a check is made to see if the user
  45. has type a halt or cancel. If a cancel is typed, then the move is stopped
  46. where it is at but the memory already moved remains moved.
  47.  
  48. the default case should never be reached if the getsize routine works properly.
  49. */
  50. /* ****************************************************** */
  51.  
  52. bmcmd(argc,argv)
  53. int argc;
  54. char *argv;
  55. {
  56.  
  57. extern int error;    /* global variable used by getnum to signal an error */
  58. register int size;    /* 1, 2 or 4 byte increments inwhich the memory will be moved*/
  59. register int count;    /* number of 1,2 or 4 byte increments that will be moved */
  60. register int start;    /* the starting address of the block move */
  61. register int addr;    /* the address to which the meory is to be moved */
  62. register int data;    /* a unit of data to be moved */
  63.  
  64.     if (argc == 3 || argc == 4)
  65.     {
  66.         striparg(argv);
  67.         size = getsize(argv,ERR04);
  68.         if (size < 0)
  69.             return(0);
  70.         for (count=0;argv[count] != COUNTDEL && !whitesp(argv[count]);++count);
  71.             ;
  72.         if (whitesp(argv[count]))
  73.             size = BYTE;
  74.         start = getnum(argv,ERR02,DEFAULTSCALE);
  75.         if (error)
  76.             return(0);
  77.         count = getcount(argv,size,start);
  78.         if (count < 0)
  79.         {
  80.             print(ERR02);
  81.             return(0);
  82.         }
  83.         addr = getnum(argv,ERR02,DEFAULTSCALE);
  84.         if (error)
  85.             return(0);
  86.         print("From : %c%8x - %c%8x\n",HEXDEL,start,HEXDEL,start + count * size - 1);
  87.         print("To   : %c%8x - %c%8x\n",HEXDEL,addr,HEXDEL,addr + count * size - 1);
  88.         if (start < addr)
  89.         {
  90.             start = start + count * size - size;
  91.             addr = addr + count * size - size;
  92.             size = -size;
  93.         }
  94.         switch (size)
  95.         {
  96.             case 1:
  97.             case -1:
  98.                 while (count > 0)
  99.                 {
  100.                     data = get8(start);
  101.                     put8(addr,data);
  102.                     start = start + size;
  103.                     addr = addr + size;
  104.                     --count;
  105.                     if(check())
  106.                         break;
  107.                 }
  108.                 break;
  109.             case 2:
  110.             case -2:
  111.                 while (count > 0)
  112.                 {
  113.                     data = get16(start);
  114.                     put16(addr,data);
  115.                     start = start + size;
  116.                     addr = addr + size;
  117.                     --count;
  118.                     if(check())
  119.                         break;
  120.                 }
  121.                 break;
  122.             case 4:
  123.             case -4:
  124.                 while (count > 0)
  125.                 {
  126.                     data = get32(start);
  127.                     put32(addr,data);
  128.                     start = start + size;
  129.                     addr = addr + size;
  130.                     --count;
  131.                     if(check())
  132.                         break;
  133.                 }
  134.                 break;
  135.             default :
  136.                 return(0);
  137.         }
  138.     }
  139.     else
  140.         print(ERR01);
  141. }
  142.                 
  143. /* ****************************************************** */
  144.  
  145.